package com.bd.scm.module.synchronization.controller;

import com.bd.scm.core.toolkit.SwaggerConstants;
import com.bd.scm.domain.dto.synchronization.SynchronizationDto;
import com.bd.scm.domain.models.synchronization.BdVisitorItems;
import com.bd.scm.domain.models.synchronization.DtAllcarsq;
import com.bd.scm.domain.models.synchronization.SmartCarhj;
import com.bd.scm.domain.models.synchronization.SmartCartemp;
import com.bd.scm.module.common.BaseController;
import com.bd.scm.module.synchronization.service.SynchronizationService;
import com.bd.utils.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiSort;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/sync")
@Api(tags = "对接停车系统接口")
@ApiSort(value = SwaggerConstants.ORDER_MODULE_VACATION)
public class SynchronizationController extends BaseController {

    private Logger log = LoggerFactory.getLogger("dataLogger");

    @Autowired
    private SynchronizationService synchronizationService;

    /**1.同步车辆合计数 数据
     * @RequestBody VisitorDto visitorDto
     * @return
     */
    @PostMapping("getVehicleCount")
    public Result getVehicleCount(@RequestBody List<SmartCarhj> smartCarhjList) {
        Result result = null;
        try {
            this.synchronizationService.disposeSmartCarhj(smartCarhjList);
            result = Result.ok("同步车辆合计数调用成功 接收数据条数:"+smartCarhjList.size());
        } catch (Exception e) {
            e.printStackTrace();
            result = Result.error("程序内部错误");
        }
        return result;
    }

    /**同步车辆进出记录 数据
     * @RequestBody VisitorDto visitorDto
     * @return
     */
    @PostMapping("getVehicleOtOfIn")
    public Result getVehicleOtOfIn(@RequestBody List<SmartCartemp> smartCartempList) {
        Result result = null;
        try {
            this.synchronizationService.disposeSmartCartemp(smartCartempList);
            result = Result.ok("同步车辆进出记录调用成功 接收数据条数:"+smartCartempList.size());
        } catch (Exception e) {
            e.printStackTrace();
            result = Result.error("程序内部错误");
        }
        return result;
    }

    /**同步访客进出记录 数据
     * @RequestBody VisitorDto visitorDto
     * @return
     */
    @PostMapping("getVisitorOtOfIn")
    public Result getVisitorOtOfIn(@RequestBody List<BdVisitorItems> bdVisitorItemsList) {
        Result result = null;
        try {
            this.synchronizationService.disposeBdVisitorItems(bdVisitorItemsList);
            result = Result.ok("同步车辆进出记录调用成功 接收数据条数:"+bdVisitorItemsList.size());
        } catch (Exception e) {
            e.printStackTrace();
            result = Result.error("程序内部错误");
        }
        return result;
    }

    /**同步车辆权限 数据
     * @RequestBody VisitorDto visitorDto
     * @return
     */
    @PostMapping("getVehicleAccess")
    public Result getVehicleAccess(@RequestBody SynchronizationDto synchronizationDto) {
        Result result = null;
        try {
            List<DtAllcarsq> dtAllcarsqList = this.synchronizationService.getDtAllcarsqList(synchronizationDto);
            result = Result.ok(dtAllcarsqList);
        } catch (Exception e) {
            e.printStackTrace();
            result = Result.error("程序内部错误");
        }
        return result;
    }
}
